YuanZhenScene={}
local NodeID = {JuDianTable=2010, GuanKouTable=2011}

YuanZhenScene.judianData = {"stronghold1","stronghold2","stronghold3","stronghold4","stronghold5"}
YuanZhenScene.guankouData = {"","","","","",""}

YuanZhenScene.getNode = function()
  YuanZhenScene.node = CCBReader:load("YuanZhenHD.ccbi")
  
  YuanZhenScene.initJuDian()
  YuanZhenScene.initGuanKou()
  return YuanZhenScene.node
end

YuanZhenScene.initGuanKou = function()
  local guankouTable = YuanZhenScene.node:getChildByTag(NodeID.GuanKouTable)
  print("YuanZhenScene.initGuanKou", guankouTable, NodeID.JuDianTable)
  guankouTable = TypeCast(guankouTable, "CCScrollView")
  local frameSize = guankouTable:getViewSize()
  
  local count = #YuanZhenScene.guankouData;
  if count<=0 then
    return
  end
  
  local sp = CCSprite:create("UI175.png")
  local itemwidth = sp:getTexture():getContentSizeInPixels().width
  --local itemwidth = 89
  local width = itemwidth * count;
 
  print("YuanZhenScene.initGuanKou", itemwidth, width, frameSize.height, frameSize.width)
  local layer = CCLayer:create()
  layer:setContentSize(CCSizeMake(width, frameSize.height))
    
  for i=0,count-1 do
    print("YuanZhenScene.initGuanKou", i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
    local sp = CCSprite:create("UI175.png")
    sp:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
    local sp1 = CCSprite:create("UI176.png")
    sp1:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2+10)
    local sp2 = CCSprite:create("UI177.png")
    sp2:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2+10)
    local sp3 = CCSprite:create("UI180.png")
    sp3:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2+10)
    local sp4 = CCSprite:create("UI178.png")
    sp4:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2-90)
    
    --[[
    local label = CCLabelTTF:create(string.format("haha%d", i), "Marker Felt", 18) 
    label:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2-45)
     local judianName = YuanZhenScene.judianData[i+1]
    local button = CCButton:createWithFileName("onJuDian", "UI74.png", "UI74.png", "UI74.png")
    button:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
    
    print("YuanZhenScene.initJuDian", i*(itemwidth+5)+(itemwidth+5)/2, frameSize.height/2)
    layer:addChild(button)
    layer:addChild(sp)
    layer:addChild(namesp)]]
    layer:addChild(sp)
    layer:addChild(sp1)
    layer:addChild(sp2)
    layer:addChild(sp3)
    layer:addChild(sp4)
  end
  --layer.setPosition(240, 160)
  --YuanZhenScene.node:addChild(layer)
  guankouTable:setContainer(layer)
end

YuanZhenScene.initJuDian = function()
  local judianTable = YuanZhenScene.node:getChildByTag(NodeID.JuDianTable)
  print("YuanZhenScene.initJuDian", judianTable, NodeID.JuDianTable)
  judianTable = TypeCast(judianTable, "CCScrollView")
  local frameSize = judianTable:getViewSize()
  local count = #YuanZhenScene.judianData;
  if count<=0 then
    return
  end
  local judianName = YuanZhenScene.judianData[1]
  sp = CCSprite:create(string.format("%s.png", judianName))
  local itemwidth = sp:getTexture():getContentSizeInPixels().width
  --local itemwidth = 64
  local width = itemwidth * count;
 
  print("YuanZhenScene.initJuDian", itemwidth, width, frameSize.height, frameSize.width)
  local layer = CCLayer:create()
  layer:setContentSize(CCSizeMake(width, frameSize.height))
    
  for i=0,count-1 do
    local judianName = YuanZhenScene.judianData[i+1]
    local button = CCButton:createWithFileName("onTestButton", "UI74.png", "UI74.png", "UI74.png")
    button:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
    local sp = CCSprite:create(string.format("%s.png", judianName))
    sp:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
    local namesp = CCSprite:create(string.format("%sf.png", judianName))
    namesp:setPosition(i*(itemwidth+10)+(itemwidth+10)/2, frameSize.height/2)
     
    print("YuanZhenScene.initJuDian", i*(itemwidth+5)+(itemwidth+5)/2, frameSize.height/2)
    layer:addChild(button)
    layer:addChild(sp)
    layer:addChild(namesp)
  end
  --layer.setPosition(240, 160)
  --YuanZhenScene.node:addChild(layer)
  judianTable:setContainer(layer)
end

YuanZhenScene.setHeadImg = function(imgname)
  local sp = CCSprite:create(imgname)
  local bksp = YuanZhenScene.node:getChildByTag(NodeID.HeadBk)
  print("bksp", bksp)
  local x,y = bksp:getPosition()
  sp:setPosition(x,y)
  YuanZhenScene.node:addChild(sp)
end


